package com.tszs.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tszs.biz.AuthorityDTO;
import com.tszs.biz.SmsConfigurationBiz;
import com.tszs.dao.mapper.SystemManageMapper;
import com.tszs.entity.SmsConfiguration;
import com.tszs.util.CallBack;
import com.tszs.util.Uuid;

/* 
* @author MRC 
* @date 2019年6月1日 上午11:09:12 
* @version 1.0 
*/
@Controller
@RequestMapping("system")
public class SystemManageController {
	
	@Autowired
	private SystemManageMapper systemManageMapper;
	
	@Autowired
	private SmsConfigurationBiz smsConfigurationBiz;
	
	/***
	 * 加载权限管理
	 * @author MRC
	 * @date 2019年6月1日上午11:10:29
	 */
	@RequestMapping("loadAuthorit")
	public void loadAuthorit(HttpServletRequest request,HttpServletResponse response){
		
		List<AuthorityDTO> lists = systemManageMapper.findAllAuthority();
		
		new CallBack().yes(response, lists, "");
	}
	
	/***
	 * 修改权限名称等
	 * @author MRC
	 * @date 2019年6月1日下午12:00:47
	 * @param request
	 * @param response
	 */
	@RequestMapping("updateAuthority")
	public void updateAuthority(HttpServletRequest request,HttpServletResponse response){
		
		String id = request.getParameter("id");
		String label =  request.getParameter("label");
		
		systemManageMapper.updateAuthority(label,id);
		systemManageMapper.updateSubAuthority(label, id);
		
		new CallBack().yes(response, "", "修改成功");
	}
	
	
	/***
	 * 保存商户银行信息
	 * @author MRC
	 * @date 2019年6月1日下午3:26:58
	 * @param request
	 * @param response
	 */
	@RequestMapping("saveBusinessBankInfo")
	public void saveBusinessBankInfo(HttpServletRequest request,HttpServletResponse response){
		
		String bankAccount = request.getParameter("bankAccount");
		String openBankName =  request.getParameter("openBankName");
		String bankName =  request.getParameter("bankName");
		String bankAddress =  request.getParameter("bankAddress");
		
		//删除参数
		systemManageMapper.deleteBankInfo("bankAccount","openBankName","bankName","bankAddress");
		//存储
		SmsConfiguration ba = new SmsConfiguration();
		ba.setAdminId(Uuid.getUUID());
		ba.setsPass("bankAccount");
		ba.setsConten(bankAccount);
		smsConfigurationBiz.insertSelective(ba);
		
		ba.setAdminId(Uuid.getUUID());
		ba.setsPass("openBankName");
		ba.setsConten(openBankName);
		smsConfigurationBiz.insertSelective(ba);

		ba.setAdminId(Uuid.getUUID());
		ba.setsPass("bankName");
		ba.setsConten(bankName);
		smsConfigurationBiz.insertSelective(ba);
		
		ba.setAdminId(Uuid.getUUID());
		ba.setsPass("bankAddress");
		ba.setsConten(bankAddress);
		smsConfigurationBiz.insertSelective(ba);
		
		new CallBack().yes(response, "", "修改成功");
	}
	
	
	/**
	 * 加载银行信息
	 * @author MRC
	 * @date 2019年6月1日下午4:05:42
	 * @param request
	 * @param response
	 */
	@RequestMapping("loadBankInfo")
	public void loadBankInfo(HttpServletRequest request,HttpServletResponse response){
		
		
		SmsConfiguration bankAccount = smsConfigurationBiz.queryOnlineService("bankAccount");
		SmsConfiguration openBankName = smsConfigurationBiz.queryOnlineService("openBankName");
		SmsConfiguration bankName = smsConfigurationBiz.queryOnlineService("bankName");
		SmsConfiguration bankAddress = smsConfigurationBiz.queryOnlineService("bankAddress");
		
		Map<String, String> map = new HashMap<>();
		
		map.put("bankAccount", bankAccount == null?"":bankAccount.getsConten());
		map.put("openBankName", openBankName == null?"":openBankName.getsConten());
		map.put("bankName", bankName == null?"":bankName.getsConten());
		map.put("bankAddress", bankAddress == null?"":bankAddress.getsConten());
		
		new CallBack().yes(response, map, "");
	}
		
}
